public class mst_02_03 {
    static ListNode root = new ListNode(4);
    static ListNode node2 = new ListNode(5);
    static ListNode node3 = new ListNode(1);

    //    面试题 02.03. 删除中间节点 简单
    public static void main(String[] args) {
        System.out.println("node3地址："+node3);
        //System.out.println(node3);
//        ListNode node4 = new ListNode(9);
//        ListNode node5 = new ListNode(8);
//        ListNode node6 = new ListNode(7);
//        ListNode node7 = new ListNode(3);
        root.next = node2;
        node2.next = node3;
        node3.next = null;
//        node3.next = node4;
//        node4.next = node5;
//        node5.next = node6;
//        node6.next = node7;
        show(root);
        //deleteNode(node3);
        new mst_02_03().deleteLastNode(root,node3);
       // System.out.println(a);
        show(root);
        System.out.println("node3地址："+node3);
        node3 = null;
        System.out.println("node3地址："+node3);
        // System.out.println(node7);
        show(root);
        System.out.println("node3地址："+node3);
        System.out.println("node2.next地址为："+node2.next);
    }

    public static void deleteNode(ListNode node) {
//        while (node.next != null) {
//           node.val = node.next.val;
//            if(node.next.next == null){
//                node.next = node.next.next;
//                break;
//            }
//            node = node.next;
//        }
        node.val = node.next.val;
        node.next = node.next.next;
    }
    public  void deleteLastNode(ListNode node,ListNode last){
       // System.out.println(s);
        ListNode tmp = node;
        while (tmp.next !=null){
            tmp = tmp.next;
        }
        //tmp.next = tmp.next.next;
        tmp = null;
        last = null;
    }

    public static void show(ListNode node) {
        ListNode tmp = node;
        while (tmp.next != null) {
            System.out.print(tmp.val + "->");
            tmp = tmp.next;
        }
        System.out.println(tmp.val);
    }
}


class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}
